package com.example.springmvcdemo3;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class MessageWallController {
    private List<MessageInfo> messageList = new ArrayList<>();
    @RequestMapping("/publish")
    public boolean publish(MessageInfo message) {
        if (!StringUtils.hasLength(message.getFrom()) ||
        !StringUtils.hasLength(message.getTo()) ||
        !StringUtils.hasLength(message.getSay())) {
            return false;
        }

        messageList.add(message);
        return true;
    }

    @RequestMapping("/getList")
    public List<MessageInfo> getList() {
        return messageList;
    }
}
